<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@page import="com.sinodata.bsm.center.util.spring.SpringContextHolder"%>
<%@page import="com.sinodata.bsm.center.service.resource.ResService"%>
<%@ page import="com.sinodata.bsm.common.vo.*" %>
<%@ page import="com.sinodata.bsm.common.utils.*" %>
	<%@ include file="../include/taglib.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<%
ResService service = SpringContextHolder.getBean(ResService.class);
String resid = request.getParameter("resid");

%>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<meta http-equiv="pragma" content="no-cache" />
	<meta http-equiv="cache-control" content="no-cache" />
	<meta http-equiv="expires" content="0" />

		<%@ include file="../include/taglib.jsp"%>
	<%@ include file="../include/common.jsp"%>
	<%@ include file="../include/table.jsp"%>
	<link href="/bsm/style/default/bsm/tab.css" rel="stylesheet" type="text/css">
<link rel="stylesheet"  type="text/css" href="${pageContext.request.contextPath}/style/default/bsm/appviewdetail.css" />
<script type="text/javascript" src="${pageContext.request.contextPath}/js/jquery/jcarousellite_1.0.1.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath}/resources/charts/FusionCharts.js"></script>
<title>中科金财IT综合监控系统</title>
	<style type="text/css">
		.xTable{ display:block; float:left;width:100%; height:100%;}
		html,body {
			overflow-x:hidden;
		}
		table.newTable thead th{
			marigin:0;
			padding:0;
		}
		.newTable{
			border-bottom:1px solid #e9e9e9;
		}
		.xTable td{
			vertical-align:top;
		}
		.w-200{
			width:30%;
			float:left;
		}
		.w-500{
			float:right;
			width:70%;
		}
		.w-500 a{
			float:right;
			width:auto;
			background-position-x:0px;
			padding-left:0;
			text-decoration:none;
			cursor:pointer;
		}
		.w-500 a:hover{
			text-decoration:underline;
		}
		table.newTable td{
			height:auto;
			line-height:35px;
		}
		.titleTh td{
			line-height:16px !Important;
			color:#888;
			text-indent:12px;
			background:url(../../style/default/images/titleTh.gif) no-repeat left top;
			}
		.dataTd td{
			height:35px;
			line-height:35px;
			font-size:15px;
			font-weight:600;
			text-align:center;
			}
		.renlin{
			background:url('${pageContext.request.contextPath}'/style/default/bsm/images/ack.gif) no-repeat 12px 3px;
		}
		.clear_1{
			background:url('${pageContext.request.contextPath}'/style/default/bsm/images/confirm.gif) no-repeat 12px 3px;		
		}
		
	</style>

<script type="text/javascript">
	//得到当前选中的
		function fnGetSelected() {   
			var selections = $("input[name='eventCheck']:checked");
			return selections;
		}
		function datagrid(){
			var oTable=	$('#eventList').dataTable();
			oTable.fnPageChange("first",true);
		}
		function cancelAllCheck(){
			$("#dt_check_all").removeAttr("checked");
		}
		function batchAck(){
			var rows = fnGetSelected();
			if(rows.length>0){
				var id = new Array(rows.length);
				var oTable =$('#eventList').dataTable();
				for(var i = 0 ; i<rows.length;i++){
					id[i] = rows[i].value;
				}
				//校验是否有权限
				$.ajax({
					   type: "POST", 
					   url: "${pageContext.request.contextPath}/event/active-event!handelAuth.action?id="+id, //请求的action
					   data: "", //传的参数
					   dataType: 'json',
					   success: function(data){ //结果
						   if(data == true){
							 //校验是否包含已认领事件
								$.ajax({
									   type: "POST", 
									   url: "${pageContext.request.contextPath}/event/active-event!ackCheck.action?id="+id, //请求的action
									   data: $("#myform").serialize(), //传的参数
									   dataType: 'json',
									   success: function(data){ //结果
										   if(data == true){
											   	var url ="iframe:event/active-event!input.action?id="+id;
												var opt = { title: "批量认领活动事件",width:600,height:180,buttons: {}};
												getTopWin(window).openjBox(url,opt,'ack-active-event',window);
										   }else{
											   datagrid();
											   getTopWin(window).getMessageBox().alert("包含已认领或清除事件","提示");
										   }
									   }
								});
						   }else{
							   getTopWin(window).getMessageBox().alert("没有认领权限","提示");
						   }
					   }
				});
			}else{
				getTopWin(window).getMessageBox().alert("请选择一条数据","提示");
			}
	  }
	  function batchConfirm(){
			var rows = fnGetSelected();
			if(rows.length>0){
				var id = new Array(rows.length);
				var oTable =$('#eventList').dataTable();
				for(var i = 0 ; i<rows.length;i++){
					id[i] = rows[i].value;
				}
				//校验是否有权限
				$.ajax({
					   type: "POST", 
					   url: "${pageContext.request.contextPath}/event/active-event!handelAuth.action?id="+id, //请求的action
					   data: "", //传的参数
					   dataType: 'json',
					   success: function(data){ //结果
						   if(data == true){
							 //校验是否包含已认领事件
							   $.ajax({
								   type: "POST", 
								   url: "${pageContext.request.contextPath}/event/active-event!confirmCheck.action?id="+id, //请求的action
								   data: $("#myform").serialize(), //传的参数
								   dataType: 'json',
								   success: function(data){ //结果
									   if(data == true){
										   var url ="iframe:${pageContext.request.contextPath}/event/active-event!delete.action?id="+id;
											var opt = { title: "批量清除活动事件",width:600,height:280,buttons: {}};
											getTopWin(window).openjBox(url,opt,'confirm-active-event',window);
									   }else{
										   datagrid();
										   getTopWin(window).getMessageBox().alert("包含已清除事件","提示");
									   }
								   }
							});
						   }else{
							   getTopWin(window).getMessageBox().alert("没有清除权限","提示");
						   }
					   }
				});
			}else{
				getTopWin(window).getMessageBox().alert("请选择一条数据","提示");
			}
		}
	  function showMessage(message){
			window.setTimeout(function () { $.jBox.tip(message, 'success'); }, 100);
		}
		function eventDown(){
			var str=document.getElementsByName("level");
	    	var objarray=str.length;
	    	var level = new Array();
	    	var j = 0;
	    	for (i=0;i<objarray;i++)
	    	{
	    	  if(str[i].checked == true)
	    	  {
	    		  level[j++]=(str[i].value);
	    	  }
	    	}
	    	//状态
	    	var statusStr=document.getElementsByName("status");
	    	var statusArray=statusStr.length;
	    	var status = new Array();
	    	var k = 0;
	    	for (i=0;i<statusArray;i++)
	    	{
	    	  if(statusStr[i].checked == true)
	    	  {
	    		  status[k++]=(statusStr[i].value);
	    	  }
	    	}
			window.location="${pageContext.request.contextPath}/event/event-export!doExport.action?level="+level+"&status="+status+"&resId="+'<%=resid%>';
		}
var filterValue =null ;
function onclickLevel(tempIndex){
	var arrayLevel = ["0","1","2","3","4","5"];
	filterValue = arrayLevel[tempIndex];
	var oTable = $('#eventList').dataTable();
	oTable.fnPageChange("first", true);
}

// 全选
function allClick() {
	var dt_check_all = $('#dt_check_all').attr("checked");
	var allCheckbox = $("input[name='eventCheck']");
	if (dt_check_all) {
		allCheckbox.attr("checked", allCheckbox); // 全选
		$('#eventList tbody tr').addClass('row_selected'); // 背景色全选
	} else {
		allCheckbox.attr("checked", false); // 取消全选
		$('#eventList tbody tr').removeClass('row_selected'); // 背景色取消
	}
}
function showDataTable() {
	var oTable = $('#eventList').dataTable({
				"bProcessing" : true,
				"bServerSide" : true,
				"sServerMethod" : 'POST',
				"sAjaxSource" : '${pageContext.request.contextPath}/event/active-event!resActiveEvents.action',
				"bPaginate" : true,
				"bSort" : true,
				"bFilter" : false,
				"bScrollCollapse":true,
				"bJQueryUI" : false,
				"sPaginationType" : "full_numbers",
				"iDisplayLength" : 10,
				"sDom":'rt <"bottom"flpi>',
				"aLengthMenu" : [[10, 20, 50, 100], [10, 20, 50, 100]],
				"aoColumns" : [{"mDataProp" : "checkbox","bSortable" : false,"fnCreatedCell" : function(nTd, sData,oData, iRow,iCol) {
									$(nTd).html("<div style='text-align:center;'>"+sData+"</div>");
							  }},
							  {"mDataProp" : "statu","bSortable" : false,"fnCreatedCell" : function(nTd, sData,oData, iRow,iCol) {
									var statusName = "<div class='status"+oData.statu+"'></div>";
									var status= oData.statu;
									var html = "<a id='"+oData.id+"_s' title='"+oData.statuValue+"' >"+ statusName +"</a>";
									$(nTd).html(html);
							}}, 
							{"mDataProp" : "levelName","bSortable" : false,"fnCreatedCell" : function(nTd, sData,oData, iRow,iCol) {
								var html ="<a id='"+oData.id+"_l' title='"+sData+"' ><div class='eventlevel"+oData.level+"'></div></a>";
								$(nTd).html(html);
							}}, 
							{"mDataProp" : "msg","bSortable" : false,"fnCreatedCell" : function(nTd, sData,oData, iRow,iCol) {
								var html ="<a href='${pageContext.request.contextPath}/event/event-view!view.action?id="+oData.id+"'target='_blank'>"+sData+"</a>";
								$(nTd).html(html);
							}},
						    {"mDataProp" : "eventTypeName","bSortable" : false},
						    {"mDataProp" : "resName","bSortable" : false},
						    {"mDataProp" : "occurTime","bSortable" : true}, 
						    {"mDataProp" : "id","bVisible" : false}, 
						    {"mDataProp" : "level","bVisible" : false}
							],
				"oLanguage" : {
					"sLengthMenu" : "每页 _MENU_ 条",
					"sZeroRecords" : "  ",
					"sInfo" : "当前从 _START_ 到 _END_ 条,共 _TOTAL_ 条记录",
					"sInfoEmpty" : "没有找到记录",
					"oPaginate" : {"sFirst" : "首页","sPrevious" : "上一页","sNext" : "下一页","sLast" : "尾页"
					}
				},
				"fnServerParams" : function(aoData) {
					aoData.push({"name" : "resId","value" : '<%=resid%>'});
					if(filterValue!=null){
						aoData.push({"name" : filterValue<=1?"FILTER_IN_Istatus":"FILTER_IN_Ilevel_","value" : filterValue});
					}
				},
				"fnInfoCallback":function( oSettings, iStart, iEnd, iMax, iTotal, sPre ) {
					var json =$.parseJSON(oSettings.jqXHR.responseText);
					$('#level2').text(json.level2==null?"":json.level2);
					$('#level3').text(json.level3);
					$('#level4').text(json.level4);
					$('#level5').text(json.level5);
					$('#claimOk').text(json.claimOk);
					$('#claimNo').text(json.claimNo);
					$('#allEvent').text(json.allEvent);
				}
			});
}
$(document).ready(function() {
	//加载grid
	initTop();
	showDataTable();
});

</script>
</head>
<body>
  <div class="max">
   		<jsp:include page="viewdetailtop.jsp">
        	<jsp:param name="resid" value="<%=resid %>" ></jsp:param>
        		<jsp:param name="pageno" value="4" ></jsp:param>
         </jsp:include>
	<!-- begin event -->
	<div class="column">
			<div class="toolbar w-200" id = "toolbar" >
			<a class="page_add renlin" href="#" onclick="batchAck()">认领</a>
	 		<a class="page_delete" href="#" onclick="batchConfirm()" >清除</a>
	 		<a class="page_excel" href="#" onclick="eventDown()" >导出</a>
	 		
	</div>
	
	<div class="toolbar w-500" id = "toolbar" >
			<a onclick="onclickLevel('');"><div id="eventlevel">全部(<label id="allEvent" class="allEvent" ></label>)</div></a>
	 		<a id="eventlevel2" class="eventlevel2" onclick="onclickLevel('2');"><div id="eventlevel2">轻微(<label id="level2" class="statuValue" ></label>)</div></a>
	 		<a id="eventlevel3" class="eventlevel3" onclick="onclickLevel('3');"><div id="eventlevel3">警告(<label id="level3" class="statuValue" ></label>)</div></a>
	 		<a id="eventlevel4" class="eventlevel4" onclick="onclickLevel('4');"><div id="eventlevel4">重要(<label id="level4"  class="statuValue"></label>)</div></a>
	 		<a id="eventlevel5" class="eventlevel5" onclick="onclickLevel('5');"><div id="eventlevel5">严重(<label id="level5" class="statuValue"></label>)</div></a>
	 		<a class="status0" onclick="onclickLevel('0');"><div id="status0">未认领(<label id="claimNo" class="statuValue"></label>)</div></a>
	 		<a class="status1" onclick="onclickLevel('1');"><div id="status1">已认领(<label id="claimOk" class="statuValue"></label>)</div></a>
	</div>

	<table id="eventList" width="100%" cellpadding="0" cellspacing="0" border="0" class="display">
		<thead>
			<tr>
				<th width="20px"><input style="position:static;" title="全选" type='checkbox' name='dt_check_all' id="dt_check_all" onclick="allClick()" /></th>
				<th width="30px">状态</th>
				<th width="30px">级别</th>
				<th >事件内容</th>
				<th width="20%">事件类别</th>
				<th width="10%">资源名称</th>
				<th width="20%">产生时间</th>
			</tr>
		</thead>
	</table>
	<div>
	<!-- end event -->
	</div>
</body>
</html>

